layui.use(['form', 'layer','laydate','upload'], function(){
	  var form = layui.form
	  ,layer = layui.layer
	  ,laydate = layui.laydate
	  ,upload = layui.upload
	  ,$ = layui.$;
	  
	  //得到用户ID
	  var usersId = user.usersId;
	  $("#usersId").val(usersId);
	  
	  //提交表单
	  $("#submit").click(function(){
		  var formArr = $("#myform").serializeArray();
		  for(var i=1;i<formArr.length;i++){
			  if(formArr[i].value == "" || formArr[i].value == null){
				  $("#"+formArr[i].name).attr("style","border:1px solid red;width:300px;");
				  layer.msg("必填项不能为空!",{icon:5,time:1000,anim:6})
				  return;
			  }
		  }
		  
		  var url = "../user/saveOrUpdate.action";
		  var data = $("#myform").serialize();
		  $.ajax({
			  url:url,
			  data:data,
			  success:function(msg){
				  if(msg.state == "1"){
					  layer.msg(msg.msg,{time:1500},function(){
						  var index = parent.layer.getFrameIndex(window.name);  
						    parent.layer.close(index);//关闭当前页
					  });
				  }else {
					  layer.msg(msg.msg,{time:1500},function(){
						  var index = parent.layer.getFrameIndex(window.name);  
						    parent.layer.close(index);//关闭当前页
					  });
				  }
			  }
		  });
	  });
	  
	  //消除掉必填项的样式
	  $(".layui-input").blur(function(event){
		  var obj = event.target;
		  var value = $(obj).val();
		  if(value != null && value != ""){
			  $(obj).attr("style","width:300px;");
		  }
	  });
	  
	  //限制手机号码数字输入
	  $("#usersPhone").keyup(function(event){
			var obj = event.target;
			var phone = $(obj).val();
			//限制只能输入数字的正则表达式
			var reg = new RegExp("^[0-9]*$");
			if(!reg.test(phone)){
				$(obj).val("");
				return false;
				//限制长度
			}else if(phone.length > 11){
				$(obj).val(phone.substring(0,11));
			}
		})
	//手机号码正则表达式
	  $("#usersPhone").blur(function(){
		var obj = event.target;
		var phone = $(obj).val();
		//验证输入有效的手机号码
		if(!(/^1[34578]\d{9}$/.test(phone))){
	    	layer.msg('请输入有效的手机号码!', {icon:5,time:1000,anim:6});
	    	$(obj).val("");
	        return false; 
	    }
	  });
	  
	  //限制身份证号数字英文输入
	  $("#usersSfz").keyup(function(event){
		  var obj = event.target;
		  var sfz = $(obj).val();
		//限制只能输入数字的正则表达式
			var reg = new RegExp("^[0-9]*$");
			if(!reg.test(sfz)){
				$(obj).val("");
				return false;
				//限制长度
			}else if(sfz.length > 18){
				$(obj).val(sfz.substring(0,18));
			}
	  })
	  
	  //身份证号正则表达式
	  $("#usersSfz").blur(function(){
		  var obj = event.target;
			var sfz = $(obj).val();
			var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
			//验证输入有效的手机号码
			if(!reg.test(sfz)){
		    	layer.msg('请输入有效的身份证号码!', {icon:5,time:1000,anim:6});
		    	$(obj).val("");
		        return false; 
		    }
	  });
	});